package com.msa.msaportal.dao.impl;


import java.util.List;

import com.msa.msaportal.common.hibernate.Finder;
import com.msa.msaportal.common.hibernate.HibernateBaseDao;
import com.msa.msaportal.common.hibernate.HibernateSimpleDao;
import com.msa.msaportal.common.page.Pagination;
import com.msa.msaportal.dao.IPortalRoleDao;
import com.msa.msaportal.entity.PortalFunction;
import com.msa.msaportal.entity.PortalRole;

public class PortalRoleDaoImpl extends HibernateBaseDao<PortalRole, Integer> implements IPortalRoleDao {

	

	@Override
	public void saveRole(PortalRole portalRole) {

		this.sessionFactory.getCurrentSession().save(portalRole);
		
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<PortalRole> getRolelist() {
		Finder finder = Finder.create();
		String hql = "from PortalRole";
		finder.append(hql);
		return find(finder);
	}

	@Override
	protected Class<PortalRole> getEntityClass() {

		return null;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<PortalFunction> getFunctionlist() {
		Finder finder = Finder.create();
		String hql = "from PortalFunction";
		finder.append(hql);
		return find(finder);
	}

	@Override
	public PortalFunction findById(Integer functionId) {
		PortalFunction portalFunction = (PortalFunction) this.getSession().get(PortalFunction.class, functionId);
		return portalFunction;
	}

	@Override
	public PortalRole findObjById(Integer roleId) {
		PortalRole portalRole = (PortalRole) this.getSession().get(PortalRole.class, roleId);
		return portalRole;
	}

	@Override
	public void updateRole(PortalRole portalRole) {
		
		this.getSession().update(portalRole);
	}

	@Override
	public void deleteRole(PortalRole portalRole) {
		
		this.getSession().delete(portalRole);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<PortalRole> findRoleByattr(String roleName) {
		Finder finder = Finder.create();
		String hql = "from PortalRole bean where bean.role_name like :rolename";
		finder.append(hql);
		finder.setParam("rolename", "%"+roleName+"%");
		return find(finder);
	}

	@Override
	public Pagination findRolepage(String roleName, int pageNo, int pageSize) {
		Finder finder = Finder.create();
		String hql = "from PortalRole bean where 1=1";
		finder.append(hql);
		if(roleName!=null && !"".equals(roleName)){
			finder.append(" and bean.role_name like :rolename");
			finder.setParam("rolename", "%"+roleName+"%");
		}
				
		return find(finder, pageNo, pageSize);
	}



}
